package com.cy.cy_plugin;

import java.io.File;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * Count the number of java files in the project
 */
@Mojo(name = "statistics", defaultPhase = LifecyclePhase.PACKAGE)
public class CyMoJo extends AbstractMojo {
	
	private int count;
	public void execute() throws MojoExecutionException {
		getJavaFile(System.getProperty("user.dir"));
		 System.out.println("total is"+count); 
	}
	
	private void getJavaFile(String basedir){
		File file=new File(basedir);
		File[] listfile = file.listFiles();  
		for(int i=0;i<listfile.length;i++){
			if (!listfile[i].isDirectory()) {
				String fileName=listfile[i].getName();
				if (fileName.substring(fileName.lastIndexOf(".")+1).equals("java")) {
					count++;
					System.out.println("file"+count+"---path=" + listfile[i]);
				}
			}else{
				getJavaFile(listfile[i].toString());
			}
		}
	}
}
